package com.ruanmou.vip.rabbitmq.demo.route;

import com.rabbitmq.client.Channel;
import com.ruanmou.vip.rabbitmq.demo.util.RabbitMQUtil;

/**
 * 欢迎同学们来到牧码人教育
 *
 * @Classname RouteSend
 * @Description TODO
 * @Date 2020-3-7 14:47
 * @Created by Gerry
 */
public class RouteSend implements PBCConfig {
    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMQUtil.getConnection().createChannel();
        channel.exchangeDeclare(EXCHANGE_NAME, DIRECT_TYPE);
        try {
            // 开启事务
            channel.txSelect();
            channel.basicPublish(EXCHANGE_NAME, "insert", null, "发布订阅模式推送消息".getBytes());
            channel.basicPublish(EXCHANGE_NAME, "hit", null, "发布订阅模式推送消息".getBytes());
            System.out.println("消息推送完成");
            // throw new RuntimeException("fdffddf");
            // 提交事务
            channel.txCommit();
        } catch (Exception e) {
            channel.txRollback();
        } finally {

            channel.close();
        }
    }
}
